package com.retirement.evaluate.service.impl;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.retirement.information.domain.OldInformation;
import com.retirement.information.mapper.OldInformationMapper;
import com.retirement.staff.domain.OldStaff;
import com.retirement.staff.mapper.OldStaffMapper;
import com.retirement.evaluate.domain.OldEvaluate;
import com.retirement.evaluate.mapper.OldEvaluateMapper;
import com.retirement.evaluate.service.IOldEvaluateService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lijy
 * @since 2024-01-04
 */
@Service
public class OldEvaluateServiceImpl extends ServiceImpl<OldEvaluateMapper, OldEvaluate> implements IOldEvaluateService {

    @Resource
    private OldInformationMapper oldInformationMapper;

    @Resource
    private OldStaffMapper oldStaffMapper;

    @Override
    public int addEvaluate(OldEvaluate dto) {
        OldInformation oldInformation = oldInformationMapper.selectById(dto.getInformationId());
        Assert.isTrue(ObjectUtil.isNotNull(oldInformation), "无用户信息");
        OldStaff oldStaff = oldStaffMapper.selectById(dto.getStaffId());
        Assert.isTrue(ObjectUtil.isNotNull(oldStaff), "无员工信息");
        dto.setId(IdUtil.simpleUUID());
        float total;
        total = dto.getRespect()+dto.getService()+dto.getCare()+dto.getPatience()+dto.getActive()+dto.getResponsibility()
                +dto.getCommunication();
        dto.setTotal(total);
        dto.setCreateTime(LocalDateTime.now());
        dto.setUpdateTime(LocalDateTime.now());

        return baseMapper.insert(dto);
    }
}
